<template>
	<view class="content">
		<u-navbar :fixed="false" :title="titleName" :autoBack="true" :safeAreaInsetTop="true" leftIconColor="#fff">
			<view slot="right">
				<m-bubble type="list" :selectData="formMenus" position="right" topOpsotion="right" bgcRgba="#fff"
					color="#333" @selectFun="TapPopup">
					<u-icon name="more-dot-fill" color="#fff" class="moremenu"></u-icon>
				</m-bubble>
			</view>
		</u-navbar>

		<view class="content_main">
			<view style="background-color: #fff;margin-bottom: 16rpx;">
				<!-- 顶部卡片 -->
				<view style="padding: 20rpx;">
					<view class="content_main_CardBox TopCard x-f">
						<view class="CardInfo">
							<m-field labelFontSize="36rpx" labelColor="#fff" labelWeight="600" paddings="10rpx"
								@click="$utils.TextCopyFun(mainTitle)" :borderBottom="false">
								<template #custom-label>
									<view class="x-f">
										<text>{{mainTitle}}</text>

										<uni-icons v-if="mainTitle" fontFamily="CustomFontPlatform" color="#f1f1f1"
											style="margin-left: 4rpx;"
											size="16">{{$utils.toUniCode('&#xe862;')}}</uni-icons>
									</view>
								</template>
							</m-field>


							<!-- <m-field labelFontSize="28rpx" labelColor="#fff" labelWeight="600" paddings="10rpx"
								@click="$utils.TextCopyFun('套票-XSDD-20240612-00011')" :borderBottom="false"
								label="套票-XSDD-20240612-00011"></m-field> -->

							<m-field style="margin-top: 18rpx;" labelFontSize="24rpx" labelColor="#fff"
								v-for="item in mainForm" paddings="0rpx" :borderBottom="false" :label="item.name+':'"
								:value="item.value" valueColor="#fff" valueFontSize="24rpx">
							</m-field>

						</view>

						<view class="CardTag">
							<!-- <view class="x-c myTag" v-for="tag in tagForm">
								<text>{{tag.text}}</text>
							</view> -->
							<u-tag :text="tag.text" v-for="tag in tagForm" style="margin-left: 10rpx;" size="large"
								plain plainFill shape="circle" :type="tag.type"></u-tag>


						</view>
					</view>
				</view>

				<!-- 表单数据 -->
				<u-cell-group :border="false">
					<view v-for="(childForm,index) in childFormList">
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="合计:"
							:value="showChildFormTableDataLen()"></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" :title="totalFunc.colDesc"
							:value="totalFunc.summaryData" v-for="totalFunc in childForm.totalFunctions"></u-cell>
					</view>
				</u-cell-group>
			</view>

			<!-- 吸顶Tab栏 -->
			<u-sticky style="background-color: #fff;top: 0 !important;box-shadow: 0 8px 11px -19px;">
				<u-tabs :list="TabList" :is-scroll="false" :current="tabCurrent" @change="clickTabItem"
					activeStyle="color: #51d0d0;" lineWidth="50" lineColor="#51d0d0" :scrollable="false">
					<template #TabText="{element,index}">
						<view style="font-size: 28rpx;">{{element.name}}</view>
					</template>
				</u-tabs>
			</u-sticky>

			<view class="MainBox">
				<!-- 商品信息 -->
				<view class="Main_CardListBox" v-if="tabCurrent == 0" v-for="(childForm,index) in childFormList">
					<view class="content_main_CardBox" v-for="(item,idx) in childForm.tableData"
						style="margin-bottom: 10rpx;">
						<view class="FiledBox">
							<text class="FiledBox_label_f28"
								v-if="childForm.titleCol.colType!=2">{{ item[childForm.titleCol.colName]}}</text>
							<text class="FiledBox_label_f28"
								v-else="childForm.titleCol.colType==2">{{ showActualValue(item[childForm.titleCol.colName],childForm.titleCol ) }}</text>
						</view>
						<!-- <view class="content_main_CardBox_RightTop y-end"
							style="position: absolute;right: 10rpx;top: 20rpx;">
							<view class="FiledBox">
								<text class="FiledBox_label_f28">500.00</text>
							</view>
							<view class="FiledBox">
								<text class="FiledBox_label_f28">X1</text>
							</view>
						</view> -->
						<view class="FiledBox" v-for="col in childForm.columns" v-if="!col.isHidden && !col.isTitle">
							<text class="FiledBox_label_f24 FiledBox_grifola">{{ col.colDesc }}:</text>
							<text class="FiledBox_value FiledBox_value_f24 FiledBox_grifola"
								v-if="col.colType!=2">{{item[col.colName] }}</text>

							<text class="FiledBox_value FiledBox_value_f24 FiledBox_grifola"
								v-if="col.colType==2">{{showActualValue(item[col.colName],col) }}</text>
						</view>

					</view>
				</view>


				<!-- 单据信息 -->
				<!-- <view class="Main_CardListBox" v-if="tabCurrent == 1">
					<u-cell-group :border="false" style="padding: 10rpx;background-color: #fff;">
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="预售款余额"
							value="35732.00"></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="应收款余额"
							value="-35732.00"></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="true" title="需要开票" value="否"></u-cell>

						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="业务员" value=""></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="true" title="部门" value=""></u-cell>

						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="送货地址" value=""></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="合同号" value=""></u-cell>
						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="true" title="项目" value=""></u-cell>

						<u-cell :titleStyle="{'fontSize': '28rpx'}" :border="false" title="单据备注" value=""></u-cell>
					</u-cell-group>
				</view> -->


				<!-- 联查信息 -->
				<view class="Main_CardListBox" v-if="tabCurrent == TabList.length-1">
					<u-cell-group :border="false" style="padding: 10rpx;background-color: #fff;">
						<u-cell v-for="(item,index) in objDetailModelList" :key="index" @click="openDetailPage(item)"
							:titleStyle="{'fontSize': '28rpx'}" :border="false" :title="item.Title"
							:valueColor="item.APPUrl ? '#4499ec' : '#333'" :value="item.BillNO"></u-cell>
					</u-cell-group>
				</view>
			</view>

		</view>


		<view class="content_bottom1 x-ec " :style="$utils.disposeSafeBottomFun()">
			<!-- content_bottom_primary_Btn -->
			<button class="CommonBtnSize workBtn" plain v-for="btn in workList" style="margin-left: 10px;"
				v-if="btn_showCondition(2,btn)" @click="selfWorkHandler(btn)">
				{{ btn.name }}
			</button>
			<button class="CommonBtnSize content_bottom_primary_Btn" style="margin-left: 10px;"
				@click="toEdit">编辑</button>
		</view>

	</view>
</template>

<script>
	import layerFun from '@/common/comFun/layerFun.js';
	var layer = layerFun;


	var vm;
	export default {
		data() {
			return {
				titleName: '详情',
				detailName: '',
				physicalTableName: '',
				keyName: '',
				keyValue: '',
				mainTitle: '',
				mainForm: [],
				tagForm: [],
				formData: {},
				formMenus: [{
						name: '单据设置',
						value: '',
						icon: 'order'
					},
					{
						name: '刷新',
						value: '',
						icon: 'reload'
					}
				],

				pageWhere: [0, 0, 0], // 记录切换tab后，前一项所在位置
				tabCurrent: 0, // 选中tab项索引
				TabList: [],
				childFormList: [],
				changeDataSource: [],
				workList: [],
				objDetailModelList: [],
				lastCallCom: 0, // 节流
			};
		},
		created() {
			var that = this;
			vm = that;
			//详情页对象名称，具体id值
			let menuDetailObj = this.$store.state.MenuDetail;
			that.detailName = menuDetailObj.detailName;
			that.keyName = menuDetailObj.keyName;
			that.keyValue = menuDetailObj.keyValue;
			that.titleName = menuDetailObj.detailTitle.replace('列表', '') + '详情';
			that.mainTitle = menuDetailObj.dataInfo.titleColName;
			that.mainForm = menuDetailObj.dataInfo.showColumnsInfo;
			that.tagForm = menuDetailObj.dataInfo.tagColumnsInfo;
			that.initConfig(that.detailName);
		},
		onUnload() {
			uni.$off('newListData');
		},
		onLoad() {
			let that = this;
			// 监听刷新
			uni.$on('FormInitToRefresh', (data) => {
				if (!that.$utils.isEmpty(data) && data.hasOwnProperty('To') && data.To != 'list') {
					that.initConfig(that.detailName);
				}
			})


			// 监听list回写的数据
			uni.$on('newListData', (ret) => {
				if (!that.$utils.isEmpty(ret)) {
					that.tagForm = ret.data;
				}
			})

		},
		methods: {
			post(sql, param, callBack) {
				param["sql"] = sql;
				if (vm.Request.getUserInfo()) {
					if (!param.hasOwnProperty("P_UserID")) {
						param.P_UserID = vm.Request.getUserInfo().UserID;
					}
					if (!param.hasOwnProperty("P_UserName")) {
						param.P_UserName = vm.Request.getUserInfo().UserName;
					}
					if (!param.hasOwnProperty("P_UserCode")) {
						param.P_UserCode = vm.Request.getUserInfo().UserCode;
					}
				}
				vm.Request.requestByUrl("/SQLData/QuerySql", param, function(data) {
					callBack(data);
				}, function(err) {
					console.log(err)
				});
				//vm.handleSizeChange(vm.paging.pageIndex);
			},
			TapPopup(data) { // 选中气泡项
				switch (data.name) {
					case '单据设置':
						//传递当前列给到列表和表头设置
						vm.$store.commit('ChangeAndSetStateData', {
							Name1: 'FormColumnSetting',
							data: vm.columns
						});

						uni.navigateTo({
							url: '/commonPage/Form/FieldSetting',
							events: {
								reloadPage: function(data) {
									vm.$refs.paging.refresh();
								}
							}
						})
						break;
					default:
						break;
				}

			},
			clickTabItem(data) { // 点击Tab栏
				this.tabCurrent = data.index;
			},
			initConfig: function(objName) {
				var that = this;

				that.Request.requestByUrl('/AppFormDetail/GetDataByName', {
					objName: objName
				}, function(data) {

					vm.physicalTableName = data.ds[0].physicalTableName;


					if (that.keyName && that.keyValue) {
						that.Request.requestByUrl("/SQLData/GetTableByKeyId", {
							physicalTableName: vm.physicalTableName,
							keyName: that.keyName,
							keyValue: that.keyValue
						}, function(ret) {

							if (ret.ds.length > 0) {
								var result = ret.ds[0];
								vm.formData = result;
								vm.tableConfig({
									childFormList: JSON.parse(data.ds[0].childFormsConfig),
									formDesign: JSON.parse(data.ds[0].formDesignConfig),
									physicalTableName: data.ds[0].physicalTableName,
									workList: JSON.parse(data.ds[0].worksConfig),
									crudList: JSON.parse(data.ds[0].crudConfig)
								});
							}
						}, function(err) {
							console.log(err)
						});
					}
				});
			},
			tableConfig(options) {
				if (options.childFormList == null) {
					options.childFormList = [];
				}
				vm.workList = options.workList;
				vm.childFormList = options.childFormList;

				vm.TabList = [];
				for (let i = 0; i < vm.childFormList.length; i++) {
					//子表数据列表刷新
					// vm.childFormList[i].showListLoading = false;
					// vm.childFormList[i].finished = false;
					//增加子表页签
					vm.TabList.push({
						name: vm.childFormList[i].title
					});
					vm.childPageInit(vm.childFormList[i]);
				}
				// vm.TabList.push({
				// 	name: '单据信息'
				// });
				vm.TabList.push({
					name: '关联单据'
				});
				vm.link();
			},
			childPageInit(childObj) {
				var that = this;
				that.Request.requestByUrl('/AppFormList/GetDataByName', {
					objName: childObj.name
				}, function(data) {
					var filterCondition = data.ds[0]["filterCondition"];
					if (filterCondition == null) {
						filterCondition = "";
					}
					vm.childTableConfig({
						childObj: childObj,
						columns: JSON.parse(data.ds[0]["columnsConfig"]),
						params: {
							isFormList: data.ds[0]["isFormList"],
							physicalTableName: data.ds[0]["physicalTableName"],
							isPaging: data.ds[0]["isPaging"],
							filterCondition: filterCondition,
							defaultOrder: data.ds[0]["defaultOrder"],
							detailName: data.ds[0]["detailName"],
							isFormEdit: false,
							rowClassCol: data.ds[0]["rowClassCol"],
							onReadyCallBack: data.ds[0]["onReadyCallBack"],
							colClassCol: data.ds[0]["colClassCol"]
						}
					})
				});

			},
			childTableConfig(options) {
				var that = this;
				options.childObj["tableData"] = [];
				options.childObj["columns"] = options.columns;
				var filterCondition = '1=1';
				if (options.params.filterCondition) {
					filterCondition += ' and ' + options.params.filterCondition;
				}
				let connectParams = vm.formData[options.childObj['connectParams']];
				if (!connectParams) {
					filterCondition += " and 1=0 ";
				} else {
					filterCondition += " and " + options.childObj['connectParams'] + "='" + connectParams + "'";
				}

				var titleCols = options.childObj.columns.filter(function(item) {
					return item.isTitle == true
				});
				if (titleCols.length > 0) {
					options.childObj["titleCol"] = titleCols[0];
				}

				vm.Request.requestByUrl('/SQLData/GetDataByPhysicalTableNameByQueryPaging_Uniapp', {
					tableName: options.params.physicalTableName,
					columnsStr: JSON.stringify([]),
					currentCol: '',
					pageIndex: 1,
					pageSize: 9999,
					isForm: (options.params.isFormList || true).toString(),
					filterCondition: filterCondition,
					defaultOrder: options.params.defaultOrder || ''
				}, function(data) {
					var tableData = data.ds;
					console.log(tableData);
					//vm.$set(curChildObj, "tableData", data.ds);

					Vue.set(options.childObj, 'tableData', data.ds);

					// options.childObj["tableData"] = data.ds;


					vm.refreshChildCol(options.childObj);
					vm.$forceUpdate();
					// //}
					// // if (curChildObj.pageIndex == 1) {

					// // } else {
					// //     curChildObj.tableData = curChildObj.tableData.concat(data.ds);
					// // }

					// for (var i = 0; i < curChildObj.tableData.length; i++) {
					// 	curChildObj.tableData[i].objNo = (i + 1).toString();
					// 	if (!curChildObj.tableData[i].guid) {
					// 		curChildObj.tableData[i].guid = vm.guid();
					// 	}
					// }
					// if (data.ds1.length > 0) {
					// 	//绑定总长度
					// 	if (curChildObj.tableData.length >= parseInt(data.ds1[0]["@TotalCount"])) {
					// 		curChildObj.finished = true;
					// 	}
					// }
					// curChildObj.pageIndex = curChildObj.pageIndex + 1;
					// // for(var i=0;i<tableData.length;i++){
					// //   tableData[i].objNo = (i+1).toString();
					// // }
					// //
					// // vm.$set(curChildObj, "tableData",tableData );
					// vm.refreshChildCol(curChildObj);
					// vm.calSummaryData(curChildObj);

				}, function() {
					vm.tableData = [];
				});
			},
			// async refreshChildCol(childObjs) {
			// 	let childObj = this.$utils.deepClone(childObjs)

			// 	const promises = childObj.columns.map(async (column) => {
			// 		if (column.colType == 2) {
			// 			const selDetailObj = column.selDetail;

			// 			if (selDetailObj.type < 3) {
			// 				const sql = selDetailObj.dataSource;
			// 				const data = await vm.changeDataAjax(sql, "1=1");
			// 				selDetailObj.sqlDataSource =
			// 					data;
			// 			} else if (selDetailObj.type === 3) {
			// 				const valueList = [];

			// 				for (const row of childObj.tableData) {
			// 					const values = row[column.colName];
			// 					if (values) {
			// 						valueList.push(...values.toString().split(',').map(value =>
			// 							`'${value}'`));
			// 					}
			// 				}

			// 				if (valueList.length > 0) {
			// 					const data = await vm.changeDataAjax(
			// 						selDetailObj.dataSource,
			// 						`${selDetailObj.hiddenValue} IN (${valueList.join(',')})`
			// 					);
			// 					selDetailObj.sqlDataSource = data;
			// 				} else {
			// 					selDetailObj.sqlDataSource = [];
			// 				}
			// 			}
			// 		}
			// 	});

			// 	await Promise.all(promises);

			// 	await vm.calSummary(childObj);
			// 	vm.$forceUpdate();
			// },
			refreshChildCol(childObj) {
				let that = this;

				childObj.columns.forEach(item => {
					if (item.colType == 2 && item.selDetail.type < 3) {
						let sql = item.selDetail.dataSource;
						let selDetailObj = item.selDetail;
						that.changeDataAjax(sql, "1=1", function(data, requestObj) {
							requestObj['sqlDataSource'] = data;
							that.$forceUpdate();
						}, selDetailObj);
					} else if (item.colType == 2 && item.selDetail.type == 3) {
						let valueList = [];

						childObj.tableData.forEach(row => {
							if (row[item.colName]) {
								let kData = row[item.colName].toString().split(',');


								kData.forEach((kItem, kIndex) => {
									valueList.push("'" + row[item.colName].toString().split(',')[
										kIndex] + "'");
								})
							}
						});

						if (valueList.length > 0) {
							let selDetailObj = item.selDetail;
							that.changeDataAjax(item.selDetail.dataSource, item.selDetail.hiddenValue + " in (" +
								valueList.join(',') + ") ",
								function(data, requestObj) {
									requestObj['sqlDataSource'] = data;
									that.$forceUpdate();
								}, selDetailObj);
						} else {
							item.selDetail.sqlDataSource = [];
						}

					}
				})


				// for (var i = 0; i < childObj.columns.length; i++) {
				// 	//下拉框数据加载
				// 	if (childObj.columns[i].colType == 2 && childObj.columns[i].selDetail.type < 3) {
				// 		var sql = childObj.columns[i].selDetail.dataSource;
				// 		var selDetailObj = childObj.columns[i].selDetail;
				// 		vm.changeDataAjax(sql, "1=1", function(data, requestObj) {
				// 			requestObj['sqlDataSource'] = data;
				// 			vm.$forceUpdate();
				// 		}, selDetailObj);
				// 	} else if (childObj.columns[i].colType == 2 && childObj.columns[i].selDetail.type == 3) {
				// 		var valueList = [];
				// 		for (var j = 0; j < childObj.tableData.length; j++) {
				// 			//if (vm.tableData[j][vm.columns[i].selDetail.hiddenValue] != null && vm.tableData[j][vm.columns[i].selDetail.hiddenValue] != undefined && vm.tableData[j][vm.columns[i].selDetail.hiddenValue] != '') {
				// 			//    valueList.push("'" + vm.tableData[j][vm.columns[i].selDetail.hiddenValue] + "'");
				// 			//}
				// 			if (childObj.tableData[j][childObj.columns[i].colName]) {
				// 				for (var k = 0; k < childObj.tableData[j][childObj.columns[i].colName].toString().split(
				// 						',').length; k++) {
				// 					valueList.push("'" + childObj.tableData[j][childObj.columns[i].colName].toString()
				// 						.split(',')[k] + "'");
				// 				}
				// 			}
				// 		}
				// 		//var sql = "select * from (" + vm.columns[i].selDetail.dataSource + ")t";
				// 		if (valueList.length > 0) {
				// 			var selDetailObj = childObj.columns[i].selDetail;
				// 			vm.changeDataAjax(childObj.columns[i].selDetail.dataSource, childObj.columns[i]
				// 				.selDetail.hiddenValue + " in (" + valueList.join(',') + ") ",
				// 				function(data, requestObj) {
				// 					requestObj.sqlDataSource = data;
				// 					console.log(requestObj);
				// 					console.log(childObj)
				// 					vm.$forceUpdate();
				// 				}, selDetailObj);
				// 		} else {
				// 			childObj.columns[i].selDetail.sqlDataSource = [];
				// 		}
				// 	}
				// }


				vm.calSummary(childObj);
				vm.$forceUpdate();
			},
			//显示下拉数据源中的真实数据
			showActualValue(value, colObject, originValue) {
				// console.log(colObject)
				// console.log(colObject.selDetail.sqlDataSource)
				if (colObject.selDetail.sqlDataSource) {
					var curObject = colObject.selDetail.sqlDataSource.filter(function(item) {
						return item[colObject.selDetail.hiddenValue] == value
					});
					if (curObject.length > 0) {
						return curObject[0][colObject.selDetail.displayValue];
					} else if (originValue) {
						return originValue;
					} else {
						return '';
					}
				} else {
					return '';
				}
				//return '';
			},
			parseQueryString(queryString) {
				// 如果queryString不包含"?"，则默认整个字符串为URL部分  
				const [url, queryStringPart] = queryString.split('?');

				// 如果没有查询字符串部分，直接返回包含URL的结果  
				if (!queryStringPart) {
					return {
						Url: url.replace(/\.vue$/, '')
					};
				}

				let params = queryStringPart.split('&').reduce((acc, current) => {
					let [key, value] = current.split('=');
					acc[key] = value;
					return acc;
				}, {});

				params['Url'] = url.replace(/\.vue$/, '');;
				return params
			},
			openDetailPage(data) { // 点击前往关联单据
				if (this.$utils.isEmpty(data.APPUrl)) {
					return
				}

				let menu = this.$utils.deepClone(data);


				let menuData = this.parseQueryString(menu.APPUrl)
				console.log(menuData)


				var returnData = {
					detailTitle: menuData['objName'],
					detailName: menuData['objName'],
					keyName: menuData['keyName'],
					keyValue: menuData['keyValue'],
					dataInfo: {}
				}
				console.log(returnData)

				vm.$store.commit('ChangeAndSetStateData', {
					Name1: 'MenuDetail',
					data: returnData
				});


				uni.navigateTo({
					url: menuData['Url']
				})

				// if (menu['src']) {
				// 	menu['Para'] = menu['src'].split('=')[1]
				// } else {
				// 	this.$utils.msg('未配置关联单据路径')
				// 	return
				// }

				// menu['APFunName'] = menu['title'];
				// console.log(menu)

				// this.$store.commit('ChangeAndSetStateData', {
				// 	Name1: 'Menu',
				// 	data: menu
				// });

				// uni.navigateTo({
				// 	url: '/commonPage/Form/Edit',
				// 	fail(err) {
				// 		console.log(err)
				// 	}
				// })

			},
			link() {
				let that = this;
				//查询关联单据

				this.Request.request('getAppRelatedDocuments', {
					objName: that.detailName,
					KeyID: that.formData[that.keyName],
				}, (ret) => {
					if (ret.status == 200) {
						that.objDetailModelList = ret.data.ds;
					}
				}, (err) => {
					console.log(err)
				})


				// vm.post("select * from paramlink where paramName=@paramName order by sort asc ", {
				// 	paramName: this.keyName
				// }, function(data) {
				// 	// console.log(data)
				// 	if (data.ds.length) {
				// 		vm.objDetailModelList = data.ds;
				// 	}
				// })

				// 			var objName = $("#keyName").val();
				// 			var objValue = $("#keyValue").val();
				// 			vm.post("select * from paramlink where paramName=@paramName order by sort asc ", {
				// 				paramName: objName
				// 			}, function (data) {
				// 				vm.objDetailModelList = [];
				// 				for (var i = 0; i < F.ui.contextMenuTab.items.length; i++) {
				// 					F.ui.contextMenuTab.removeTab(i);
				// 				}
				// 				for (var i = 0; i < data.ds.length; i++) {
				// 					if (data.ds[i].tabType == 1) {
				// 						var searchKeyName = data.ds[i].keyName;
				// 						var searchKeyValue = 0;
				// 						//查询主键值
				// 						vm.post("select * from " + data.ds[i].tableName + " where " + objName + "='" + objValue + "'  ", {}, function (ret) {
				// 							if (ret.ds.length > 0) {
				// 								var src = data.ds[i].src + "&keyName=" + searchKeyName + "&keyValue=" + ret.ds[0][searchKeyName] + "&isView=1";
				// 								//data.ds[i].src = src;
				// 								//parent.vm.objDetailModelList.push(data.ds[i]);
				// 								var isActive = false;
				// 								if (i == 0) {
				// 									isActive = true;
				// 								}
				// 								//添加页签
				// 								F.ui.contextMenuTab.addTab({
				// 									title: data.ds[i].title,
				// 									iframe: true,
				// 									iframeUrl: src
				// 								}, false, isActive);
				// 							}
				// 						});
				// 					}
				// 					else if (data.ds[i].tabType == 2) {
				// 						var query = objName + "='" + objValue + "'";
				// 						let base64Helper = Base64;
				// 						query = base64Helper.encode(query)
				// 						var src = data.ds[i].src + "&query=" + query + "&isView=1";
				// 						//data.ds[i].src = src;
				// 						//parent.vm.objDetailModelList.push(data.ds[i]);
				// 						var isActive = false;
				// 						if (i == 0) {
				// 							isActive = true;
				// 						}
				// 						//添加页签
				// 						F.ui.contextMenuTab.addTab({
				// 							title: data.ds[i].title,
				// 							iframe: true,
				// 							iframeUrl: src
				// 						}, false, isActive);
				// 					}
				// 					else if (data.ds[i].tabType == 3) {
				// 						var src = data.ds[i].src + "&" + objName + "=" + objValue;
				// 						var isActive = false;
				// 						if (i == 0) {
				// 							isActive = true;
				// 						}
				// 						//添加页签
				// 						F.ui.contextMenuTab.addTab({
				// 							title: data.ds[i].title,
				// 							iframe: true,
				// 							iframeUrl: src
				// 						}, false, isActive);



				// 					}
				// 				}
				// 			});
				// 			F.ui.windowContextMenu.show();
				// 			F.ui.windowContextMenu.maximize();
				// 			F.ui.windowContextMenu.setTitle(vm.showDetailTitle);

			},
			//计算汇总数据
			calSummary(childObj) {
				var totalFunctions = childObj.columns.filter(function(item) {
					return item.colTotalFunction;
				});
				childObj["totalFunctions"] = totalFunctions;
				totalFunctions.forEach(function(item) {
					if (item.colTotalFunction == "sum") {
						//保留位数
						var fixNum = 2;
						var totalNum = 0;
						for (var j = 0; j < childObj.tableData.length; j++) {
							var currentNum = parseFloat(childObj.tableData[j][item.colName]);
							if (isNaN(currentNum)) {
								currentNum = 0;
							}
							totalNum += currentNum;
						}
						item["summaryData"] = totalNum.toFixed(fixNum);
					}
				});
				vm.$forceUpdate();
			},
			showChildFormTableDataLen(tableData) {
				//console.log(tableData.length)
				// return tableData.length.toString();
				var that = this;
				if (that.childFormList.length > 0 && that.childFormList[0].tableData) {
					return that.childFormList[0].tableData.length;
				} else {
					return '';
				}

			},
			async selfWorkHandler(work) { // 点击底栏自定义按钮
				let that = this;

				function throttle(fn, delay = 3000) {
					return function(...args) {
						const now = new Date().getTime();
						if (now - that.lastCallCom < delay) {
							return;
						}
						that.lastCallCom = now;
						fn.apply(this, args);
					};
				}


				await throttle(function() {
					var script = work.script.replace(/\['/g, "vm.formData['");
					script = script.replace(/\["/g, "vm.formData[\"");
					// console.log(script)
					eval(script);

				}, 2000)();

				await uni.$emit('FormInitToRefresh', {
					To: 'list',
					keyID: that.formData[that.keyName]
				})
			},
			//按钮显示条件判断
			btn_showCondition(type, btn) {
				try {
					var _this = this;
					var result = true;
					var showScript = "";

					//普通crud
					if (type == 1) {
						if (btn == "新增") {
							showScript = _this.crudList[0].show;
						} else if (btn == "编辑") {
							showScript = _this.crudList[1].show;
						} else if (btn == "删除") {
							showScript = _this.crudList[2].show;
						}
					}
					//业务按钮
					else if (type == 2) {
						showScript = btn.show;
					}
					//调入按钮
					else if (type == 3) {
						showScript = btn.btnShow;
					}
					if (showScript) {
						var script = showScript.replace(/\['/g, "_this.formData['");
						script = script.replace(/\["/g, "_this.formData[\"");
						eval("result=(" + script + ")");
					}
					return result;
				} catch (e) {
					return false;
				}
			},
			//进入编辑区域
			toEdit() {
				console.log(222)
				uni.navigateTo({
					url: '/commonPage/Form/Edit'
				})
			},
			/*系统函数结束*/
			/*change获取数据机制处理
			  用于change过程中反复调用后台处理的机制问题
			*/
			changeDataAjax: function(datasource, query, callBack, requestObj) {
				var dsResult = vm.changeDataSource.filter(function(item) {
					return item.datasource == datasource && item.query == query;
				});
				if (dsResult.length == 0) {
					var returnData = [];
					var sql = "select * from (" + datasource + ")t";
					sql += " where " + query;

					var ajaxRequest = vm.Request.PromiseRequestByUrl('/SQLData/GetDataBySql', {
						sql: sql
					});

					ajaxRequest.promise.then(function(data) {
						if (data.status == 200) {
							returnData = data.data.ds;
							vm.changeDataSource.push({
								datasource: datasource,
								query: query,
								data: returnData
							});
							callBack(returnData, requestObj);
						}
					});
				} else {
					callBack(dsResult[0].data, requestObj);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	* {
		box-sizing: border-box;
	}

	.content {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #f9f9f9;


		.content_main {
			flex: 1;
			overflow: auto;
			position: relative;


			.TopCard {
				background-color: #4499ec;

				.CardInfo {
					flex: 3;
				}

				.CardTag {
					position: absolute;
					right: 20px;
					top: 25rpx;

				}
			}
		}
	}

	.content_bottom1 {
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		height: 70px;
		line-height: 70px;
		padding: 6px 15px;
		// border-top: 1px solid #efefef;
		box-shadow: 1px 0 12px -9px #333;
		z-index: 99;

		.workBtn {
			border-color: #ddd !important;
			margin-left: 10px !important;
		}
	}
</style>